<template>
	<view class="index">
    <music-head title="网易云音乐" :show="false"/>
    <view class="container" v-show="!isLoading">
      <scroll-view scroll-y="true">
        <view class="index-search" @tap="handleToSearch">
          <text class="iconfont icon-Magnifier"></text>
          <view class="index-search-box">搜索歌曲</view>
        </view>
        <view class="index-list">
          <view class="index-list-item" v-for="(list, index) in topList" :key="index" @tap="handleToList(list.id)">
            <view class="index-list-img">
              <image :src="list.coverImgUrl"></image>
              <text class="update-time">{{ list.updateFrequency }}</text>
            </view>
            <view class="index-list-text">
              <view v-for="(item, musicIndex) in list.tracks" :key="musicIndex">{{ musicIndex + 1 }}.{{ item.first }} - {{ item.second }}</view>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>
	</view>
</template>

<script>
  import musicHead from '@/components/musicHead/musicHead.vue'
  import { topList } from '@/common/api.js'
	export default {
    name: "Index",
		data () {
			return {
        topList: [],
        isLoading: true
			}
		},
    components: {
      musicHead
    },
		onLoad () {
      uni.showLoading({
        title: '加载中...'
      })
      this.isLoading = true
      topList().then(res => {
        if (res.length) {
          this.topList = res
          this.isLoading = false
          uni.hideLoading()
        }
      })
		},
		methods: {
      handleToList (id) {
        uni.navigateTo({
          url: `/pages/list/list?id=${id}`
        })
      },
      
      handleToSearch () {
        uni.navigateTo({
          url: `/pages/search/search`
        })
      }
		}
	}
</script>

<style scoped>
  .index-search {
    display: flex;
    align-items: center;
    width: 686upx;
    height: 72upx;
    margin: 30upx 32upx 30upx 32upx;
    background: #f8f8f8;
    border-radius: 36upx;
  }
  .index-search text {
    font-size: 26upx;
    color: #bdbdbd;
    margin: 0 22upx 0 26upx;
  }
  .index-search .index-search-box {
    font-size: 26upx;
  }
  .index-list {
    margin-left: 32upx;
  }
  .index-list-item {
    height: 212upx;
    margin-bottom: 30upx;
    display: flex;
  }
  .index-list-item .index-list-img {
    position: relative;
    width: 212upx;
    height: 212upx;
    margin-right: 20upx;
  }
  .index-list-item .index-list-img image {
    width: 212upx;
    height: 212upx;
    border-radius: 12upx;
  }
  .index-list-item .index-list-img .update-time {
    position: absolute;
    left: 12upx;
    bottom: 8upx;
    font-size: 18upx;
    color: #fff;
  }
  .index-list-text view {
    font-size: 25upx;
    line-height: 68upx;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
